<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.sms.project.*" %>

<%--
	project/headman/report-detail.jsp
 --%>

<%	//清除内存
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", 0); 
%> 


<%
	request.setCharacterEncoding("utf-8");
	String userno = (String)session.getAttribute("userno");
	
	String row = request.getParameter("row");//获取该项目是第几行的参数(从0开始的)
	int num = Integer.parseInt(row);
	Project p = null;

	String progress = request.getParameter("progress");
	String condition = "";
	if(progress != null) {
		if(progress.trim().equals("already")) {
			condition = "finish";
		} else if(progress.trim().equals("unalready")){
			condition = "notfinish";
		} else {
			condition = "";
		}
	} else {
		condition = "";
	}

	//得到该项目的对象并赋值
	List<Project> llist = new ArrayList<Project>();
	llist = Task.getLProject(userno, condition, "member");
	if(llist != null && llist.size() > 0) {
		p = (Project)llist.get(num);
	} else {
		return;
	}
	
	int proID = p.getProID();
	List<PReport> prlist = Task.getPReport(proID, userno);
	List<PReport> oprlist = Task.getOtherPReport(proID, userno);
	
	/* int myTotalRecords = 0;
	int otherTotalRecords = 0;
	int totalRecords = 0;
	int totalPage = 0;
	int pageSize = 2;
	if(prlist1 != null && prlist1.size() > 0) {
		myTotalRecords = prlist1.size();
	}
	if(oprlist1 != null && oprlist1.size() > 0) {
		otherTotalRecords = oprlist1.size();
	}
	totalRecords = myTotalRecords +  otherTotalRecords;
	totalPage = (totalRecords + pageSize -1)/pageSize;
	
	if(totalPage < 1) {
		totalPage = 1;
	}
	int pageNo = 1;
	try {
		pageNo = Integer.parseInt(request.getParameter("pageNo"));
		if(pageNo < 1) {
			pageNo = 1;
		} else if(pageNo > totalPage) {
			pageNo = totalPage;
		}
	} catch(NumberFormatException e) {
		pageNo = 1;
	}
	int startPos = (pageNo -1)*pageSize;
	
	List<PReport> prlist = new ArrayList<PReport>();;
	List<PReport> oprlist = new ArrayList<PReport>();;
	if(startPos <= myTotalRecords) {
		if(myTotalRecords >= (pageNo * pageSize)) {
			prlist = Task.getPReport(proID, userno, startPos, pageSize);;
		} else {
			int n = myTotalRecords - startPos;//展示条数
			prlist = Task.getPReport(proID, userno, startPos, n);
			oprlist = Task.getOtherPReport(proID, userno, 0, pageSize - n);
		}
	} else {
		oprlist = Task.getOtherPReport(proID, userno, startPos - myTotalRecords, pageSize);
	} */
%>		

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<input type="hidden" name="row" id="row" value="<%= row %>" />
<input type="hidden" name="progress" id="progress" value="<%= progress%>" />
<input type="hidden" name="proID" id="proID" value="<%= proID%>" />
<div class="report-detail">
   项目名称：<%= p.getProName() %>&nbsp;&nbsp;<a class="easyui-linkbutton" iconCls="icon-add" id="add">添加汇报</a>
   <%--  <p style="text-align:center;" id='page'>第<%= pageNo %>页
    <% 
    	if(pageNo != 1) {
    %>
    <a href="javascript:void(0)" onclick="jump(<%= pageNo -1 %>);">上一页</a>
    <%}%>
    <% 
    	if(totalPage == 0) {
    		totalPage = 1;
    	}
    %>
   	<%
   		if(pageNo != totalPage) { 
   	%>
    		<a href="javascript:void(0)" onclick="jump(<%= pageNo + 1 %>);">下一页</a> 
    <% } %>
    	&nbsp;&nbsp;&nbsp;
    	共<%= totalPage %>页</p> --%>
<% 	//展示收到的汇报
int number = 0;
if(prlist != null && prlist.size() > 0) {
%>
<br />有关我的：
<%
	for(int i=0; i<prlist.size(); i++) {
		PReport pr = prlist.get(i);
		number++;
		System.out.println("ddd" + pr.getTaskID());
		String toname = "";
		List<String> toName = pr.getToName();
		if(toName != null && toName.size() > 0) {
			for(int j=0; j<toName.size(); j++) {
				toname += toName.get(j);
			}
		}
%>
    <div style="height:450px; overflow:scroll;" title="From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= toname %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getPrTime() %>" id="<%= pr.getPrID() %>">
       <p class="content"><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= pr.getContent() %><br/><br/>
     	<% 
     	List<Map> appendFile = null;
		//如果有附件
		if(pr.getIsAppend().equals("1")) {
			appendFile = new ArrayList<Map>();
			appendFile = pr.getAppendFile();
     %>  
   		<span class="people">
      		<label for="file">附件链接：</label>
      <% 
      	if(appendFile != null && appendFile.size() > 0) {
      		for(int m=0; m<appendFile.size(); m++) {
      				Map<String, String> map = (Map<String, String>)appendFile.get(m);
					String fileName = (String)map.get("fileName");
					String saveName = (String)map.get("saveName");
      %>
      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>&nbsp;&nbsp;&nbsp;&nbsp;
      <%
      		}
   		}
   		}
      %>
      	</span>
      		<span style="text-align:right; display:block;">
      		&nbsp;&nbsp;&nbsp;楼主
      		 <%
      			if(pr.getFromID().equals(userno) && pr.getIsleaf().equals("0")) {
      		%>
      			<a id="del" href="javascript:void(0)" onclick="del(<%= pr.getPrID() %>);">删除</a>&nbsp;&nbsp;&nbsp;
      		<%	
      			}
      		 %>
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 			<form id="rep-content<%= number %>" enctype="multipart/form-data" onSubmit="return dealReply(<%= number %>);" action="ReplyReportServlet" method="post" style="display:none;margin-left: 90px;" target="addReply_iframe<%= number %>">
    	 			<input type="hidden" name="type" id="type" value="<%= pr.getType() %>" />
	    			<input type="hidden" name="rootid" id="rootid" value="<%= pr.getRootid()%>" />
	    			<input type="hidden" name="pid" id="pid" value="<%= pr.getPrID() %>" />
	    			<input type="hidden" name="taskid" id="taskid" value="<%= pr.getTaskID() %>" />
	    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
	    			<input type="hidden" name="toid" id="toid" value="<%= pr.getFromID() %>" />
	    			<table width="95%">
		    			<tr><td><lable class="people">添加回复</lable></td></tr>
		    			<tr><td><textarea id="content<%= number %>" name="content" style="width:100%;height:150px;overflow:scroll;"></textarea></td></tr>
						<tr class="addfiles"><label for="file" class="people"><td >添加附件：</label><input type="file" id="file" name="load" style="width:125px;" /></td></tr> 
		    			<tr><td><input type="submit" name="button" value="提交内容" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		    					<input type="reset" value="重置"/>
		    			</td></tr>
	    			</table>
    			</form>
    			<iframe name="addReply_iframe<%= number %>" style="display:none;">
    			</iframe>
    	 	</span>
    </p>
    <% 
    	if(pr.getIsleaf().equals("1")) {//有回复（即非叶子节点）
    		List<PReport> prrlist = new ArrayList<PReport>();
    		prrlist.addAll(Task.getReplyReport(pr, 0));
    		if(prrlist != null && prrlist.size() >0) {
    			int n = 0;
    			for(int j=0; j<prrlist.size(); j++) {
    				PReport prr = prrlist.get(j);
    				number++;
 					
 					String toname2 = "";
					List<String> toName2 = prr.getToName();
					if(toName2 != null && toName2.size() > 0) {
						for(int m=0; m<toName2.size(); m++) {
							toname2 += toName2.get(m);
						}
					}
					
			    	String classes = "";
			    	String floor = "";
			    	if(prr.getGrade() > 1) {
			    		classes = "Reply2";
			    	} else {
			    		classes= "Reply";
			    		n ++;
			    		floor = n + "楼";
			    	}
    %>
    	<p class="<%= classes %>"><span class="people">From：<%= prr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= toname2 %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= prr.getPrTime() %><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= prr.getContent() %><br/><br/>
     			<% 
			     	List<Map> appendFile2 = null;
					//如果有附件
					if(prr.getIsAppend().equals("1")) {
						appendFile2 = new ArrayList<Map>();
						appendFile2 = prr.getAppendFile();
			     %>  
			   		<span class="people">
			      		<label for="file">附件链接：</label>
			      <% 
			      	if(appendFile2 != null && appendFile2.size() > 0) { 
			      		for(int m=0; m<appendFile2.size(); m++) {
			      				Map<String, String> map2 = (Map<String, String>)appendFile2.get(m);
								String fileName = (String)map2.get("fileName");
								String saveName = (String)map2.get("saveName");
			      %>
			      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>,&nbsp;&nbsp;&nbsp;&nbsp;
			      <%
			      		}
			   		}
		   		}
			      %>
       	 	<span style="text-align:right; display:block;">
       	 		&nbsp;&nbsp;&nbsp;<%= floor %>
       	 		 <%
      			if(prr.getFromID().equals(userno) && prr.getIsleaf().equals("0")) {
	      		%>
	      			<a id="del" href="javascript:void(0)" onclick="del(<%= prr.getPrID() %>);">删除</a>&nbsp;&nbsp;&nbsp;
	      		<%	
	      			}
	      		 %>
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 	</span>
	    	<form id="rep-content<%= number %>" enctype="multipart/form-data" onSubmit="return dealReply(<%= number %>);" action="ReplyReportServlet" method="post" style="display:none;margin-left: 90px;" target="addReply_iframe<%= number %>">
    			<input type="hidden" name="type" id="type" value="<%= prr.getType() %>" />
    			<input type="hidden" name="rootid" id="rootid" value="<%= prr.getRootid()%>" />
    			<input type="hidden" name="pid" id="pid" value="<%= prr.getPrID() %>" />
    			<input type="hidden" name="taskid" id="taskid" value="<%= prr.getTaskID() %>" />
    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
    			<input type="hidden" name="toid" id="toid" value="<%= prr.getFromID() %>" />
    			<table width="95%">
	    			<tr><td><lable class="people">添加回复    </lable></td></tr>
	    			<tr><td><textarea id="content<%= number %>" name="content" style="width:100%;height:150px;overflow:scroll;"></textarea></td></tr>
					<tr class="addfiles"><label for="file" class="people"><td >添加附件：</label><input type="file" id="file" name="load" style="width:125px;" /></td></tr> 
	    			<tr><td><input type="submit" name="button" value="提交内容" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	    					<input type="reset" value="重置"/>
	    			</td></tr>
    			</table>
    		</form>
   			<iframe name="addReply_iframe<%= number %>" style="display:none;">
   			</iframe>
   		 </p>  
    <%
    			}
    		}
    	}
    %>
    </div>
<%
	}
	}
%>

<% 	//展示其他人的汇报
if(oprlist != null && oprlist.size() > 0) {
%>
<br />其他人的汇报：
<%
	for(int i=0; i<oprlist.size(); i++) {
		PReport pr = oprlist.get(i);
		number++;
		
		String toname = "";
		List<String> toName = pr.getToName();
		if(toName != null && toName.size() > 0) {
			for(int j=0; j<toName.size(); j++) {
				toname += toName.get(j);
			}
		}
%>
    <div style="height:450px; overflow:scroll;"  title="From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= toname %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getPrTime() %>" id="<%= pr.getPrID() %>">
       <p class="content"><br />
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= pr.getContent() %><br/><br/>
     	<% 
     	List<Map> appendFile = null;
		//如果有附件
		if(pr.getIsAppend().equals("1")) {
			appendFile = new ArrayList<Map>();
			appendFile = pr.getAppendFile();
     %>  
   		<span class="people">
      		<label for="file">附件链接：</label>
      <% 
      	if(appendFile != null && appendFile.size() > 0) {
      		for(int m=0; m<appendFile.size(); m++) {
      				Map<String, String> map = (Map<String, String>)appendFile.get(m);
					String fileName = (String)map.get("fileName");
					String saveName = (String)map.get("saveName");
      %>
      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>&nbsp;&nbsp;&nbsp;&nbsp;
      <%
      		}
   		}
   		}
      %>
      	</span>
      		<span style="text-align:right; display:block;">
      		&nbsp;&nbsp;&nbsp;楼主
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 		<form id="rep-content<%= number %>" enctype="multipart/form-data" onSubmit="return dealReply(<%= number %>);" action="ReplyReportServlet" method="post" style="display:none;margin-left: 90px;" target="addReply_iframe<%= number %>">
    	 			<input type="hidden" name="type" id="type" value="<%= pr.getType() %>" />
	    			<input type="hidden" name="rootid" id="rootid" value="<%= pr.getRootid()%>" />
	    			<input type="hidden" name="pid" id="pid" value="<%= pr.getPrID() %>" />
	    			<input type="hidden" name="taskid" id="taskid" value="<%= pr.getTaskID() %>" />
	    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
	    			<input type="hidden" name="toid" id="toid" value="<%= pr.getFromID() %>" />
	    			<table width="95%">
		    			<tr><td><lable class="people">添加回复</lable></td></tr>
		    			<tr><td><textarea id="content<%= number %>" name="content" style="width:100%;height:150px;overflow:scroll;"></textarea></td></tr>
						<tr class="addfiles"><label for="file" class="people"><td >添加附件：</label><input type="file" id="file" name="load" style="width:125px;" /></td></tr> 
		    			<tr><td><input type="submit" name="button" value="提交内容" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		    					<input type="reset" value="重置"/>
		    			</td></tr>
	    			</table>
    			</form>
    			<iframe name="addReply_iframe<%= number %>" style="display:none;">
    			</iframe>
    	 	</span>
    </p>
    <% 
    	if(pr.getIsleaf().equals("1")) {//有回复（即非叶子节点）
    		List<PReport> prrlist = new ArrayList<PReport>();
    		prrlist.addAll(Task.getReplyReport(pr, 0));
    		if(prrlist != null && prrlist.size() >0) {
    			int n = 0;
    			for(int j=0; j<prrlist.size(); j++) {
    				PReport prr = prrlist.get(j);
    				number++;
 					
 					String toname2 = "";
					List<String> toName2 = prr.getToName();
					if(toName2 != null && toName2.size() > 0) {
						for(int m=0; m<toName2.size(); m++) {
							toname2 += toName2.get(m);
						}
					}
					
			    	String classes = "";
			    	String floor = "";
			    	if(prr.getGrade() > 1) {
			    		classes = "Reply2";
			    	} else {
			    		classes= "Reply";
			    		n ++;
			    		floor = n + "楼";
			    	}
    %>
    	<p class="<%= classes %>"><span class="people">From：<%= prr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= toname2 %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= prr.getPrTime() %><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= prr.getContent() %><br/><br/>
     			<% 
			     	List<Map> appendFile2 = null;
					//如果有附件
					if(prr.getIsAppend().equals("1")) {
						appendFile2 = new ArrayList<Map>();
						appendFile2 = prr.getAppendFile();
			     %>  
			   		<span class="people">
			      		<label for="file">附件链接：</label>
			      <% 
			      	if(appendFile2 != null && appendFile2.size() > 0) { 
			      		for(int m=0; m<appendFile2.size(); m++) {
			      				Map<String, String> map2 = (Map<String, String>)appendFile2.get(m);
								String fileName = (String)map2.get("fileName");
								String saveName = (String)map2.get("saveName");
			      %>
			      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>,&nbsp;&nbsp;&nbsp;&nbsp;
			      <%
			      		}
			   		}
		   		}
		      %>
       	 	<span style="text-align:right; display:block;">
       	 		&nbsp;&nbsp;&nbsp;<%= floor %>
       	 		 <%
      				if(prr.getFromID().equals(userno) && prr.getIsleaf().equals("0")) {
	      		%>
	      			<a id="del" href="javascript:void(0)" onclick="del(<%= prr.getPrID() %>);">删除</a>&nbsp;&nbsp;&nbsp;
	      		<%	
	      			}
	      		 %>
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 	</span>
	    	<form id="rep-content<%= number %>" enctype="multipart/form-data" onSubmit="return dealReply(<%= number %>);" action="ReplyReportServlet" method="post" style="display:none;margin-left: 90px;" target="addReply_iframe<%= number %>" >
    			<input type="hidden" name="type" id="type" value="<%= prr.getType() %>" />
    			<input type="hidden" name="rootid" id="rootid" value="<%= prr.getRootid()%>" />
    			<input type="hidden" name="pid" id="pid" value="<%= prr.getPrID() %>" />
    			<input type="hidden" name="taskid" id="taskid" value="<%= prr.getTaskID() %>" />
    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
    			<input type="hidden" name="toid" id="toid" value="<%= prr.getFromID() %>" />
    			<table width="95%">
	    			<tr><td><lable class="people">添加回复    </lable></td></tr>
	    			<tr><td><textarea id="content<%= number %>" name="content" style="width:100%;height:150px;overflow:scroll;"></textarea></td></tr>
					<tr class="addfiles"><label for="file" class="people"><td>添加附件：</label><input type="file" id="file" name="load" style="width:125px;" /></td></tr> 
	    			<tr><td><input type="submit" name="button" value="提交内容" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	    					<input type="reset" value="重置"/>
	    			</td></tr>
    			</table>
    		</form>
    	 	<iframe name="addReply_iframe<%= number %>" style="display:none;">
   			</iframe>
   		 </p>  
    <%
    			}
    		}
    	} 
    %>
    </div>
<%
	}
	}
%>
</div>
<div id="tt"></div>
<script type="text/javascript">
var num;
$('.report-detail').accordion({
	fit:true
	})
	
function show(i) {
	var content = "#rep-content" + i;
	$(content).appendTo($(this).parents("p")).end().css('display','block');
}
	
function disappear(i) {
	var content = "#rep-content" + i;
	$(content).appendTo($(this).parents("p")).end().css('display','none');
}

function del(i) {
if(confirm('确定要删除吗？')){
	$.ajax({
		url:'DelReportServlet',//添加链接，添加回复内容
		data:'delid=' + i,
		dataType:'text',
		success:function(msg){
		alert(msg);
		if(msg=='ok'){
			alert('删除成功');
		 	$('#dd').dialog('refresh','project/headman/report-sdetail.jsp?row=' + $('#row').attr('value') + '&progress=' + $('#progress').attr('value')); //刷新对话框,回复内容显示出来，回复输入框隐藏显示
   		}
			else{alert('删除失败');}
		}
	})
	}
}

function dealReply(i) {
	var contentNum = "#content" + i;
	var cont = $(contentNum).attr('value');
	if (cont) {
		return true;
	} 
	else {
		alert('请补充完整信息');
		return false;
	}
}

function jump(i) {
	$('#dd').dialog('refresh','project/headman/report-sdetail.jsp?row=' + $('#row').attr('value') + '&progress=' + $('#progress').attr('value') + '&pageNo=' + i);
}

function callback(msg)   
{   
 	//alert(msg);
 	if(msg=='ok'){                              
 		alert('回复成功');
 		$('#dd').dialog('close');
 		$('#dd').dialog({
		         title:"任务/信息交流",
				 zIndex:9001,
				width:820, height:490,
				 top:140,left:365,
				 maximizable:true,
				 cache:false,
				 resizable:true,
				href:'project/headman/report-sdetail.jsp?row=' + $('#row').attr('value') + '&progress=' + $('#progress').attr('value'), 
			});
 	}
 	else{
	 	alert('回复失败!');
 	}
 }
 
//添加汇报
$('#add').click(function(){
	 $('#tt').dialog({
		         title:"添加汇报",
				 zIndex:9001,
				 width:820, height:490,
		 		top:140,left:365,
				 maximizable:true,
				 cache:false,
				 resizable:true,
				href:'project/student/add-report.jsp?proID=' + $('#proID').attr('value') //记得加上相应的参数，标示汇报是哪一个项目的汇报
	})
	})
</script>
</body>
</html>
